<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card :gutter="20">
      <el-row>
        <el-col :span="8">
          <el-input ref="searchInput"
                    placeholder="请输入内容"
                    clearable
                    v-model="queryData.query"
                    @clear="getOrderList">
            <el-button @click="search"
                       slot="append"
                       icon="el-icon-search">
            </el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="orderList"
                border
                style="width: 100%">
        <el-table-column type="index"
                         label="#">
        </el-table-column>
        <!-- 数据列 -->
        <el-table-column prop="order_number"
                         label="订单编号"
                         width="500px">
        </el-table-column>
        <el-table-column prop="order_price"
                         label="订单价格"
                         width="100px">
        </el-table-column>
        <el-table-column prop="pay_status"
                         label="是否付款"
                         width="100px">
          <template slot-scope="scope">
            <el-tag type="danger"
                    v-if="scope.row.pay_status=='0'">未付款</el-tag>
            <el-tag type="success"
                    v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send"
                         label="是否发货"
                         width="100px">
        </el-table-column>
        <el-table-column prop="create_time"
                         label="下单时间"
                         width="200px">
          <template slot-scope="scope">
            {{scope.row.add_time | dateFormat}}
          </template>
        </el-table-column>
        <!-- 操作列 -->
        <el-table-column label="操作">
          <template slot-scope="">
            <el-button type="primary"
                       size="mini"
                       icon="el-icon-edit"
                       @click="isEditAddressShow = true"></el-button>
            <el-button type="success"
                       size="mini"
                       icon="el-icon-location"
                       @click="showProgressDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 页码条 -->
      <el-pagination @size-change="handleSizeChange"
                     :current-page="queryData.pagenum"
                     :page-size="queryData.pagesize"
                     @current-change="pageChange"
                     :page-sizes="[5, 10, 20, 50]"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址"
               :visible.sync="isEditAddressShow"
               v-dialogDrag>
      <!-- 级联选择器 -->
      <el-cascader v-model="selectedCityIds"
                   :options='cityList'
                   :props="{expandTrigger:'hover'}"
                   clearable></el-cascader>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="isEditAddressShow = false">取 消</el-button>
        <el-button type="primary"
                   @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度"
               :visible.sync="isProgressDialogShow"
               v-dialogDrag>
      <!-- 物流进度 -->
      <el-timeline>
        <el-timeline-item v-for="(activity, index) in wuliuProgress"
                          :key="index"
                          :timestamp="activity.ftime">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="isProgressDialogShow = false">取 消</el-button>
        <el-button type="primary"
                   @click="isProgressDialogShow = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import cityList from './citydata'
export default {
  data () {
    return {
      queryData: {
        query: '', // 查询关键字
        pagenum: 1, // 页码
        pagesize: 5 // 页容量
      },
      orderList: [],
      total: 0,
      isEditAddressShow: false, // 修改地址对话框 开关
      isProgressDialogShow: false, // 物流进度对话框 开关
      cityList, // 导入的城市数组
      selectedCityIds: [], // 选中的要修改的城市id
      wuliuProgress: [] // 物流时间节点数据
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取 订单数据列表
    async getOrderList () {
      // 异步请求 订单数据列表
      const { data: resData } = await this.$http.get('orders', { params: this.queryData })
      // 如果获取失败,显示错误提示
      if (resData.meta.status !== 200) return this.$message.error(resData.meta.msg)
      // 将返回的 角色数组 设置给 roleList
      this.orderList = resData.data.goods
      this.total = resData.data.total
    },
    // 搜索
    search () {

    },
    // 页容量改变事件处理函数
    handleSizeChange (newSize) {
      // 修改 当前页
      this.queryData.pagesize = newSize
      // 重新请求 当前页 数据
      this.getOrderList()
    },
    // 点击页码事件
    pageChange (newPage) {
      // 修改 当前页
      this.queryData.pagenum = newPage
      // 重新请求 当前页 数据
      this.getOrderList()
    },
    async showProgressDialog () {
      // 显示 物流对话框
      this.isProgressDialogShow = true
      // 请求 物流数据
      const { data: resData } = await this.$http.get('/kuaidi/9864930071719')
      // 如果失败
      if (resData.meta.status !== 200) this.$message.error(resData.meta.msg)
      // 如果成功
      // 挂载数据到data中,供视图使用
      this.wuliuProgress = resData.data
      // 显示 物流对话框
      this.isProgressDialogShow = true
    }
  }
}
</script>

<style lang="less" scoped>
</style>
